package com.hugegis.CustomView;

import com.hugegis.Service.UpDataService;
import com.hugegis.SmarHMETER.R;

import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.preference.Preference.OnPreferenceChangeListener;

public class ApplicationPreferencesActivity extends PreferenceActivity {
	
	private EditTextPreference editPrefer;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		addPreferencesFromResource(R.layout.preferences);
		Preference openUpdata = (Preference) findPreference(Strings.SETTINGS_OPEN_UPDATA);
		
		openUpdata.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
			public boolean onPreferenceChange(Preference preference, Object newValue) {
				if (Boolean.TRUE.equals(newValue)) {
					new Thread() {
						public void run() {
							startService(new Intent(ApplicationPreferencesActivity.this, UpDataService.class));
						}
					}.start();
				} else {
					stopService(new Intent(ApplicationPreferencesActivity.this, UpDataService.class));
				}
				return true;
			}
		});
		Preference openPicApplication = (Preference) findPreference(Strings.PHOTO_INTENT_KEY);
		openPicApplication.setOnPreferenceClickListener(new OnPreferenceClickListener() {
			
			@Override
			public boolean onPreferenceClick(Preference preference) {
				Intent intent=new Intent();
				ComponentName comp = new ComponentName("com.htc.album", "com.htc.album.AlbumMain.ActivityMainCarousel" );
				intent.setComponent(comp);
				startActivity(intent);
				return false;
			}
		});
		
		editPrefer=(EditTextPreference)findPreference(Strings.SETTINGS_WATER_EXCEPTION);
		editPrefer.setOnPreferenceClickListener(new OnPreferenceClickListener() {
			@Override
			public boolean onPreferenceClick(Preference preference) {
				editPrefer.getEditText().setSelection(editPrefer.getText().length());
				return true;
			}
		});
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}

}
